;+
; NAME:
;  hod_setmodel
; PURPOSE:
;  Sets the HOD model and priors in a common block
; CALLING SEQUENCE:
;  hod_setmodel[,modtab=,cosmo1=,cosmo2=,rbin=,prof=,bmdl=,comm=,ver=])
;-
@hod_common
pro hod_setmodel,$;zmod=zmod,modtab=modtab,cosmo1=cosmo1,cosmo2=cosmo2,$
                 $;rbin=rbin,prof=prof,bmdl=bmdl,comm=comm,ver=ver,$
   parfile=parfile,$
   priortype=priortype,priorspec=priorspec

COMMON hod_model

if n_elements(parfile) eq 0 then hod_parfile='default.par' $
else hod_parfile=parfile

; first read and check input parameters (if provided) or set to
; defaults
;if n_elements(zmod) eq 0 then hod_zmod=0.28 $
;else hod_zmod=zmod
;
;if n_elements(modtab) eq 0 then hod_modtab='hodtb_tweak_best3.dat' $
;else hod_modtab=modtab
;
;if n_elements(cosmo1) eq 0 then hod_cosmo1=[0.7,0.3,0.7] $
;else if n_elements(cosmo1) ne 3 then $
;  message,"cosmo1 must have 3 elements" $
;else hod_cosmo1=cosmo1
;
;if n_elements(cosmo2) eq 0 then hod_cosmo2=[0.85,0.045,0.97] $
;else if n_elements(cosmo2) ne 3 then $
;  message,"cosmo2 must have 3 elements" $
;else hod_cosmo2=cosmo2
;
;if n_elements(rbin) eq 0 then hod_rbin=[0.05,80,60] $
;else if n_elements(rbin) ne 3 then $
;  message,"rbin must have 3 elements" $ 
;else hod_rbin=rbin
;
;
;if n_elements(prof) eq 0 then hod_prof='nfw' $
;else if prof ne 'nfw' and prof ne 'm99' then $
;  message,"prof must be 'nfw' or 'm99'" $
;else hod_prof=prof
;
;if n_elements(bmdl) eq 0 then hod_bmdl='TIN05' $
;else if bmdl ne 'TIN05' and bmdl ne 'SMT01' and bmdl ne 'ST99' then $
;  message,"bmdl must be 'TIN05', 'SMT01' or 'ST99'" $
;else hod_bmdl=bmdl
;
;if n_elements(comm) eq 0 then hod_comm='wp_xi_ccf3_plth_tbl2' $
;else hod_comm=comm
;
;if n_elements(ver) eq 0 then hod_ver=3 $
;else hod_ver=ver


;;;
; Now setting the initial model parameters and priors
hod_npar=6  ; do these vary depending on the model???
hod_ndim=6
parnames=['Log(M_sat1)','Log(M_eq1)','alpha1','Log(M_cen1)']
initpars=[12.0,13.5,0.5,12.0]

if n_elements(priortype) gt 0 and n_elements(priorspec) gt 0 then begin
    hod_priortype=priortype
    hod_priorspec=priorspec
endif else begin
    print,"Specify model priortype and priorspec"
    print," Priortype: 0=delta fn 1=constant    2=logconst    3=Gaussian"
    print," Priorspec: val        lolim,uplim   lolim,uplim   mean,sigma"
    hod_priortype=intarr(hod_ndim)
    hod_priorspec=fltarr(2,hod_ndim)
    
    for ipar=0,hod_ndim-1 do begin
        good=0
        while good eq 0 do begin
            readin=' '
            read,prompt=parnames[ipar]+"(type spec)",readin,format='(A)'
            splt=strsplit(readin,' ',/extract)
            if n_elements(splt) gt 0 then begin
                if splt[0] eq '0' then begin
                    hod_priortype[ipar]=0
                    if n_elements(splt) ge 2 then begin
                        hod_priorspec[0,ipar]=splt[1]*1.0
                        hod_priorspec[1,ipar]=0.0
                        good=1
                    endif
                endif
                
                if splt[0] eq '1' then begin
                    hod_priortype[ipar]=1
                    if n_elements(splt) ge 3 then begin
                        hod_priorspec[*,ipar]=splt[1:2]*1.0
                        good=1
                    endif
                endif
                
                if splt[0] eq '2' then begin
                    hod_priortype[ipar]=2
                    if n_elements(splt) ge 3 then begin
                        hod_priorspec[*,ipar]=splt[1:2]*1.0
                        good=1
                    endif
                endif
                
                if splt[0] eq '3' then begin
                    hod_priortype[ipar]=3
                    if n_elements(splt) ge 3 then begin
                        hod_priorspec[*,ipar]=splt[1:2]*1.0
                        good=1
                    endif
                endif
            endif
        endwhile
    endfor
endelse

 print," finished model specification"
end
